package com.jweb.framework.core.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 修改人： Thomas
 * 修改内容：新增 
 * 类说明：在ApplicationContext环境外获取bean的工具类
 */
public class ApplicationContextHelper implements ApplicationContextAware {
	
	public void setApplicationContext(ApplicationContext context) throws BeansException {
		ApplicationContextHolder.getInstance().setApplicationContext(context);
	}
	
	public static ApplicationContext getApplicationContext(){
		return ApplicationContextHolder.getInstance().getApplicationContext();
	}
	
	public static <T> T getBean(Class<T> clazz) {
		return ApplicationContextHolder.getInstance().getApplicationContext().getBean(clazz);
	}
	
	public static <T> T getBean(String name) {
		return (T)ApplicationContextHolder.getInstance().getApplicationContext().getBean(name);
	}
}
